<?php

namespace App\Admin\Extensions;

use Encore\Admin\Form\Field;

class WangEditor extends Field
{
    protected $view = 'admin::form.editor';

    protected static $css = [
        '/packages/wangEditor-2.1.23/dist/css/wangEditor.min.css',
    ];

    protected static $js = [
        '/packages/wangEditor-2.1.23/dist/js/wangEditor.min.js',
    ];

    public function render()
    {

        $token = csrf_token();
        $this->script = <<<EOT
var editor = new wangEditor('{$this->id}');

     editor.config.fontsizes = {  // 字号配置，增加14px
                // 格式：'value': 'title'
                1: '12px',
                2: '13px',
                3: '14px',
                4: '16px',
                5: '18px',
                6: '24px',
                7: '32px',
                8: '48px'
     };


    // 上传图片（举例）
    editor.config.uploadImgUrl = '/admin/editor_upload';

    // 配置自定义参数（举例）
    editor.config.uploadParams = {
        _token: '{$token}',
    };
    
    editor.config.uploadImgFileName = 'wang-editor-image-file';

    // 设置 headers（举例）
    editor.config.uploadHeaders = {
        'Accept' : 'text/x-json'
    };

    // 隐藏掉插入网络图片功能。该配置，只有在你正确配置了图片上传功能之后才可用。
    editor.config.hideLinkImg = false;


    editor.create();

EOT;
        return parent::render();

    }
}